<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-col :span="24">
            <a-form-item label="举办人Id" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['userId', validatorRules.userId]" placeholder="请输入举办人Id" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="比赛类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['type', validatorRules.type]" placeholder="请输入比赛类型" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="是否回收鱼获" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['recycleFish']" placeholder="请输入是否回收鱼获" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['name']" placeholder="请输入标题" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['status', validatorRules.status]" placeholder="请输入状态" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['phone']" placeholder="请输入联系电话" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="参赛费/元" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['entryFee']" placeholder="请输入参赛费/元" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="奖金/元" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['bonus']" placeholder="请输入奖金/元" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="服务费/元" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['serviceFee']" placeholder="请输入服务费/元" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="开赛时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择开赛时间" v-decorator="['startTime']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="结赛时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择结赛时间" v-decorator="['endTime']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="人数下限" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['limitDown']" placeholder="请输入人数下限" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="人数上限" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['limitUp']" placeholder="请输入人数上限" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="钓场名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fishpondName']" placeholder="请输入钓场名称" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="钓场地域" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fishpondArea']" placeholder="请输入钓场地域" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="钓场详细地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fishpondAddress']" placeholder="请输入钓场详细地址" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="鱼讯" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea v-decorator="['fishInfo']" rows="4" placeholder="请输入鱼讯" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="放鱼量（公斤）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fishAmount']" placeholder="请输入放鱼量（公斤）" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="钓场图片" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea v-decorator="['images']" rows="4" placeholder="请输入钓场图片" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="成绩公正图" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['scoreImage']" placeholder="请输入成绩公正图" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="赛事规定" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['description']" placeholder="请输入赛事规定" ></a-input>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: "ZmGameModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
          userId: {
            rules: [
              { required: true, message: '请输入举办人Id!'},
            ]
          },
          type: {
            rules: [
              { required: true, message: '请输入比赛类型!'},
            ]
          },
          status: {
            rules: [
              { required: true, message: '请输入状态!'},
            ]
          },
        },
        url: {
          add: "/admin/zmGame/add",
          edit: "/admin/zmGame/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'userId','type','recycleFish','name','status','phone','entryFee','bonus','serviceFee','startTime','endTime','limitDown','limitUp','fishpondName','fishpondArea','fishpondAddress','fishInfo','fishAmount','images','scoreImage','description'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'userId','type','recycleFish','name','status','phone','entryFee','bonus','serviceFee','startTime','endTime','limitDown','limitUp','fishpondName','fishpondArea','fishpondAddress','fishInfo','fishAmount','images','scoreImage','description'))
      },

      
    }
  }
</script>